package main.Q1401_1500;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Q1411_1420 {
    public static void main(String[] args) {
        System.out.println("Question1411：");
        System.out.println("Question1412：");
        System.out.println("Question1413：");
        System.out.println("Question1414：");
        System.out.println("Question1415：长度为 n 的开心字符串中字典序第 k 小的字符串");
        System.out.println("Question1416：");
        System.out.println("Question1417：");
        System.out.println("Question1418：");
        System.out.println("Question1419：数青蛙");
        System.out.println("Question1420：");
    }
}

class Question1415 {
    List<String> result = new ArrayList<>();

    public void process(String lastStr, int n, char lastChar) {
        if (n == 0) {
            result.add(lastStr);
            return;
        }
        if (lastChar != 'a') {
            process(lastStr + "a", n - 1, 'a');
        }
        if (lastChar != 'b') {
            process(lastStr + "b", n - 1, 'b');
        }
        if (lastChar != 'c') {
            process(lastStr + "c", n - 1, 'c');
        }
    }

    public String getHappyString(int n, int k) {
        process("", n, ' ');
        if (result.size() < k) return "";
        else return result.get(k - 1);
    }
}

class Question1419 {
    public int minNumberOfFrogs(String croakOfFrogs) {
        if (croakOfFrogs.length() % 5 != 0) {
            return -1;
        }
        int result = 0, frogNum = 0;
        int[] counts = new int[4];
        Map<Character, Integer> map = new HashMap<Character, Integer>() {{
            put('c', 0);
            put('r', 1);
            put('o', 2);
            put('a', 3);
            put('k', 4);
        }};
        for (int i = 0; i < croakOfFrogs.length(); i++) {
            char c = croakOfFrogs.charAt(i);
            int t = map.get(c);
            if (t == 0) {
                counts[t]++;
                frogNum++;
                if (frogNum > result) {
                    result = frogNum;
                }
            } else {
                if (counts[t - 1] == 0) {
                    return -1;
                }
                counts[t - 1]--;
                if (t == 4) {
                    frogNum--;
                } else {
                    counts[t]++;
                }
            }
        }
        if (frogNum > 0) {
            return -1;
        }
        return result;
    }
}